<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class City extends MX_Controller {


	function __construct()
	{
		parent::__construct();
		$this->load->model('location/location_model');
		$this->load->model('category/category_model');
	}

	public function index($stateID=0, $offset=0, $limit=5)
	{
		$data['city'] = $this->location_model->get_city($stateID, $offset, $limit);
		$this->load->view('city',$data);
	}

	function all(){
		$stateID = $this->commoncall->get_id(current_url());
		$this->template->set_layout('static');
		$data['city'] = $this->location_model->get_city($stateID,999999999,0);
		
		$data['statename'] = $this->location_model->get_region_data($stateID)->statename;
		
		
		
		$data['site_title'] = $this->settings_model->siteInfo('web_title');
		
		$this->template->set_breadcrumb('Home', '/')
		//->set_breadcrumb('Category','')
		->set_breadcrumb('Region','location/region/all')
		->set_breadcrumb($data['statename'],'');
		
		
		$this->template->set_partial('nav_bar','header/nav_bar');
		$this->template->set_partial('header_search','header/header_search');
		$this->template->build('city_all',$data);
	}
	
	function find_location(){
			
		$search = $_GET['term'];
		$query = $this->db->query("SELECT id,cityname FROM `city` WHERE `cityname` LIKE '%$search%' ORDER BY cityname ASC limit 10") or die('Something went wrong');
		$result = $query->result();
		$row_set = array();
	
		foreach ($result as $row1){
			$row = array(
					'label'	=> stripslashes($row1->cityname),
					'value'	=> 	(int)$row1->id
			);
			$row_set[] = $row;//build an array
		}
	
		echo json_encode($row_set);//format the array into json data
	
	}
	
	public function clear_location(){
		redirect('location/city/clear_city');
	}
	
	function clear_city(){
	
	
		if (isset($_COOKIE["cook_cityname"])){
			$this->input->set_cookie("cook_city", 0, 0);
			$this->input->set_cookie("cook_cityname", "", 0);
				
		}
	
		//if($this->input->cookie('cook_cityname')){
		//var_dump($this->input->cookie('cook_cityname'));
		delete_cookie('cook_cityname');
		//var_dump($this->input->cookie('cook_cityname', false));
		//$this->input->set_cookie("cook_cityname", "Siliguri", time()+3600*30);
		//return TRUE;
		//	}
	
	
	}
	
	//--Get cities--rahul--//
	function get_cities($stateID){
		header('Content-Type: application/x-json; charset=utf-8');
		echo(json_encode($this->location_model->get_cities_by_state($stateID)));
		die();
	}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
